export const request = (options, config) => {
    return new Promise((resolve, reject) => {
        $.ajax({
            url        : options.url,
            type       : options.method,
            data       : options.data,
            headers    : options.headers,
            timeout    : config.timeout ?? 0,
            dataType   : 'json',
            cache      : false,
            processData: false,
            contentType: false,
            crossDomain: true,
        })
            .done((result) => {
                if (config.onBeforeResponse) {
                    const error = config.onBeforeResponse(result);
    
                    if (error) {
                        reject(error);
                        return;
                    }
                }

                resolve(result);
            })
            .fail((e) => reject(e));
    });
};
